package com.venus.service.impl;

import com.venus.entity.Massage;
import com.venus.entity.Register;
import com.venus.mapper.UserMapper;
import com.venus.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import static com.alibaba.druid.util.Utils.md5;

/**
 * Created by lanou on 18/3/1.
 */
@Service
public class UserServiceImpl implements UserService{
    @Resource
    private UserMapper userMapper;

    @Override
    public Register valiName(Register register) {
        Register register1 =userMapper.valiName(register);
        return register1;
    }

    @Override
    public void register(Register register) {
            userMapper.register(register);
    }

    @Override
    public int findUid(Register register) {
        int id = userMapper.findUid(register);
        return id;
    }

    @Override
    public void registerInsert(int id) {
        userMapper.registerInsert(id);
    }

    @Override
    public Massage findMassage(int id) {
        Massage massage = userMapper.findMassage(id);
        return massage;
    }

    @Override
    @Transactional
    public void upMassage(int id, Massage massage) {
        userMapper.upMassage(id,massage);
        userMapper.upUser(id,massage);
    }

//    @Override
//    public void upUser(int id, Massage massage) {
//        userMapper.upUser(id,massage);
//    }

    @Override
    public boolean valiPwd(String username,String pwd) {
        String pwd1 = userMapper.valiPwd(username);
        if(pwd1.equals(md5(pwd))){
            return true;
        }
        return false;
    }

    @Override
    public void upPwd(String username, String newpwd) {
        userMapper.upPwd(username,newpwd);
    }

    @Override
    public void upImg(int id, String avatar) {
        userMapper.upImg(id,avatar);
    }
}
